package helpers;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

public class LanguageHepler {
	
	private static List<String> languages = new ArrayList<String>(Arrays.asList("en", "es", "pt"));
	
	public static List<String> getLanguages() {
		return languages;
	}
	
	public static String getLanguage(HttpServletRequest request) {
		String language = "en";
		
		String url = UrlHelper.getServerUrl(request);
		language = getLanguage(url);
		
		return language;
	}
	
	public static String getLanguage(String url) {
		String firstSubDomain = UrlHelper.getFirstSubDomain(url);
		String language = "en";
		if (languages.contains(firstSubDomain)) {
			language = firstSubDomain;
		}
		
		return language;
	}
}
